﻿using Moven.ViewModels;
using System.Collections.Generic;

namespace Moven.Views
{
    public partial class MenuPage
    {
		public class HomeMenuItemViewModel : BaseViewModel
		{
			public HomeMenuItemViewModel()
			{
				MenuType = MenuType.About;
			}
			public MenuType MenuType { get; set; }

			bool _isSelected;
			public bool IsSelected
			{
				get { return _isSelected; }
				set { SetProperty(ref _isSelected, value); }
			}
		}

        RootPage root;
        List<HomeMenuItemViewModel> menuItems;
        public MenuPage(RootPage root)
        {
            InitializeComponent();
			this.root = root;
			
            BindingContext = new BaseViewModel
            {
                Title = "墨文",
                Subtitle = "墨文",
                Icon = "slideout.png"
            };

            menuListView.ItemsSource = menuItems = new List<HomeMenuItemViewModel>
                {
                    new HomeMenuItemViewModel
                    {
                        Title = "所有墨文",
                        MenuType = MenuType.AllArticles,
                        Icon ="article.png",
						IsSelected = true
                    },
                    new HomeMenuItemViewModel
                    {
                        Title = "标签分类",
                        MenuType = MenuType.Tags,
                        Icon ="tag.png"
                    },
                    new HomeMenuItemViewModel
                    {
                        Title = "收藏",
                        MenuType = MenuType.Bookmarks,
                        Icon = "bookmark.png"
                    },
                    new HomeMenuItemViewModel
                    {
                        Title = "搜索",
                        MenuType = MenuType.Search,
                        Icon ="magnify.png"
                    },
                    new HomeMenuItemViewModel
                    {
                        Title = "关于",
                        MenuType = MenuType.About,
                        Icon ="about.png",
						IsSelected = false
                    }
                };

            menuListView.ItemSelected += async (sender, e) =>
                {
                    if (e.SelectedItem == null)
                        return;
					menuListView.SelectedItem = null;
					
					var menuItem = (HomeMenuItemViewModel)(e.SelectedItem);
					menuItems.ForEach(item => item.IsSelected = item.MenuType == menuItem.MenuType);
					await this.root.NavigateAsync(menuItem.MenuType);
                };
        }
    }
}

